﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameLibrary
{
    using Tile;
    /// <summary>
    /// Gamemanger helper
    /// </summary>
    public static class GMHelper
    {
        #region random
        internal static Random Rand;
        internal static void SetRand(Random rand)
        {
            Rand = rand;
        }
        #endregion
        #region player bias
        internal static float median = 0.5f;
        static internal int max = 11;
        internal static Bias GetBias()
        {
            return  new Bias()
            {
                Build = new BuildRatio(
                    GMHelper.Rand.Next(1, max),
                    GMHelper.Rand.Next(1, max),
                    GMHelper.Rand.Next(1, max),
                    GMHelper.Rand.Next(1, max),
                    GMHelper.Rand.Next(1, max)),
                WarSpendingInTotalIncome = (float)Rand.NextDouble()
            };
        }
        #endregion
        #region map
        public static int Height { get; private set; }
        public static int Width { get; private set; }
        public static int RegionWidth = 5;
        public static int RegionHeight = 5;
        public static int RegionSize = 25;
        internal static void SetHeight(int height)
        {
            if (height > 0)
                Height = height;
            else
                throw new ArgumentException("Height > 0");
        }
        internal static void SetWidth(int width)
        {
            if (width > 0)
                Width = width;
            else
                throw new ArgumentException("Width > 0");
        }

        /// <summary>
        /// Randomly generate map.
        /// </summary>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        internal static TileType[,] GenerateMap()//int width, int height)
        {
            TileType[,] map = new TileType[GMHelper.Width, GMHelper.Height];
            for (int i = 0; i < GMHelper.Width; i++)
                for (int j = 0; j < GMHelper.Height; j++)
                    map[i, j] = GetTileType(Rand.Next(6));
            return map;
        }

        private static TileType GetTileType(int n)
        {
            switch (n)
            {
                case 0:
                case 1:
                case 2:
                    return TileHelper.Plain;
                case 3:
                case 4:
                    return TileHelper.Hill;
                case 5:
                    return TileHelper.Mountain;
            }
            throw new Exceptions.ShouldNotReachException("Tile type does not exist.");
        }
        #endregion
    }
}
